package dto

import (
	"engine/model"
	"lib/db"
)

func GetTaskByUIds(uId uint64) (model.My_task, error) {
	var userNew model.My_task
	err := db.GetDb().Where("uid = ? ", uId).Order("id desc").First(&userNew).Error
	if err != nil {
		return userNew, nil
	}
	return userNew, nil
}

func GetTaskByUId(uId uint64) (*model.My_task, error) {
	var userNew model.My_task
	err := db.GetDb().Where("uid = ? ", uId).Order("id desc").First(&userNew).Error
	if err != nil {
		return nil, nil
	}
	return &userNew, nil
}

func GetTaskCount(uId uint64, types int) int64 {
	var count int64
	if types == 0 {
		db.GetDb().Table("my_user").Where("(pid = ? or ppid = ?) and is_task>0", uId, uId).Count(&count)
	} else {
		db.GetDb().Table("my_user").Where("pid = ? or ppid = ? and is_task>0", uId, uId).Count(&count)
	}
	return count
}

func GetTodayTask(uId uint64, days string) int64 {
	var count int64

	db.GetDb().Table("my_my_task").Where("tid = 13 and uid=? and days=?", uId, days).Count(&count)

	return count
}
